﻿using System;
using System.Collections.Generic;
using System.Linq;
using NFine.Code;
using NFine.Domain.Entity.SystemManage;
using NFine.Domain._03_Entity.Biz;
using NFine.Domain._04_IRepository.Biz;
using NFine.Repository.Biz;

namespace NFine.Application.Biz
{
    public class BalanceRecordApp
    {
        private IBalanceRecordRepository balanceRecordRepository = new BalanceRecordRepository();

        public List<BalanceRecordEntity> GetListForBalance(Pagination pagination, string yearRecord)
        {
            var expression = ExtLinq.True<BalanceRecordEntity>();
            
            if (!string.IsNullOrEmpty(yearRecord))
            {
                DateTime start = new DateTime(Convert.ToInt32(yearRecord), 1, 1);
                DateTime end = start.AddYears(1);
                
                expression = expression.And(a => a.F_BalanceTime >= start && a.F_BalanceTime < end);
            }
            string sss = expression.ToString();

            List<BalanceRecordEntity> list = balanceRecordRepository.FindList(expression, pagination).OrderByDescending(a => a.F_BalanceTime).ToList();
            

            return list;
        }
    }
}